using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Webadmin_ConfigPreview : bzAdminPageBase
{    
    public string strUserOnline = "";
    public string strPreviewInfo = "";
      
    public dbConnection _DB = new dbConnection();

    protected override void loadAction()
    {
        if (!this.Page.IsPostBack)
        {
            switch (this.Act)
            {
                case "Kick":
                    this.doKick();
                    break;
            }
        }
    }


    private void doKick()
    {
        string strName = Request.QueryString["Name"] == null ? "" : Request.QueryString["Name"];
        SqlParameter p = new SqlParameter("@UserName", strName);         
        if (_DB.updateData("SP_updateAdminUser_Kick",p) > 0)
            Response.Write(bzStringClass.addStringAlert(this.AdminLang["Success"]));
        Response.Write(bzStringClass.redirectClient("ConfigPreview.aspx"));
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.initSiteLang(bzSiteOption.Group.Administrator, bzSiteOption.None, "LeftMenu");
        this.strUserOnline = this.getUserOnline();
        this.strPreviewInfo = this.getPreview();
    }
    private string getUserOnline()
    {
        string str = "";
        DataTable dt = _DB.getDataTable("SP_getAdminUserOnline");
        foreach (DataRow dr in dt.Rows)
        {
            TimeSpan t = DateTime.Now - Convert.ToDateTime(dr["LoginTime"]);
            if (t.TotalSeconds < Convert.ToInt64(this.SiteOption["LoginTime"]))
            {
                if (dr["AdminUser"].ToString().Trim().ToUpper() != Session["AdminUser"].ToString().Trim().ToUpper() && Session["AdminLevel"].ToString() == "1")
                    str += "<div style=\"float:left; vertical-align:middle;font-size:8pt\"><strong>" + dr["AdminUser"].ToString() + "  <a href=\"ConfigPreview.aspx?Act=Kick&Name=" + dr["AdminUser"].ToString() + "\" class=\"no_under\"><img border=\"0\" src=\"../../images/icon/permission.gif\" title=\"" + this.AdminLang["ConfigPreview_Kick"].ToString() + "\"/></a></strong> - IP:  " + dr["IP"].ToString() + "</div><div style=\"clear:both\"></div>";
                else 
                    str += "<div style=\"float:left; vertical-align:middle;font-size:8pt\"><strong>" + dr["AdminUser"].ToString() + "</strong> - IP:  " + dr["IP"].ToString().Split('_')[0] + "</div><div style=\"clear:both\"></div>";
            }
        }
        return str;
    }
    private string getPreview()
    {
        string str = "";
        DataTable dtGroup = _DB.getDataTable("SP_getAdminFunctionGroup");
        foreach (DataRow dr in dtGroup.Rows)
        {
            SqlParameter p = new SqlParameter("@GroupName",dr["GroupName"].ToString());            
            DataTable dt = _DB.getDataTable( "SP_getAdminFunction_Preview",p);
            if (dt.Rows.Count > 0) str += "<tr><td colspan=\"2\" height=\"18\" class=\"box_title\" >&nbsp;" + this.AdminLang[dr["GroupName"].ToString()].ToString() + "</td></tr>";
            foreach (DataRow drSub in dt.Rows)
            {
                SqlParameter spt = new SqlParameter("@Table", drSub["TableName"].ToString());
                str += "<tr><td width=\"60%\" height=\"22\" valign=\"top\" align=\"right\">&nbsp;<a href=\"../../" + drSub["URL"].ToString() + "\" >" + this.AdminLang[drSub["FunctionName"].ToString()].ToString() + "</a></td><td width=\"40%\" height=\"22\" valign=\"top\" align=\"left\" >" + _DB.getTotalTable("SP_getTotal" ,spt).ToString() + "</td></tr>";
            }
        }      
        return str;
    } 
    
}
